package chapter2;

import java.util.Random;

/**
 * @author ycj
 * @version 1.0
 * @description: TODO
 * @date 2022/5/17
 */
public class Source2_9 {
    static int data=0;
    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
            try {
                Thread.sleep(new Random().nextInt(50));
                data = 1;
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        thread.start();

        try {
            thread.join();
            //一个线程终止后对于共享变量的更新 对于对于调用该线程join方法的线程是可见的
            System.out.println("data="+data);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
